package com.winit.requirement.manager;

import com.winit.common.util.Constants;
import com.winit.commons.util.SeqGenerate;
import com.winit.requirement.model.ReqDebunker;
import com.winit.requirement.model.ReqRemark;
import com.winit.requirement.repository.ReqDebunkRepository;
import com.winit.requirement.repository.ReqDebunkRepositoryExt;
import com.winit.requirement.repository.ReqRemarkRepositoryExt;
import com.winit.requirement.repository.ReqRemarksRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.util.List;

@Component
public class ReqDebunkManager {
    private static Logger log = LoggerFactory.getLogger(ReqDebunkManager.class);

    @Autowired
    private ReqDebunkRepository repository;

    @Autowired
    ReqDebunkRepositoryExt reqDebunkRepositoryExt;


    public ReqDebunker create(ReqDebunker debunker) {
        if (StringUtils.isEmpty(debunker.getId())) {
            debunker.setId(SeqGenerate.createId("RD"));
        }
        Assert.isTrue(!StringUtils.isEmpty(debunker.getReqId()), "req id 不能为空");

        debunker.setIsImprove(Constants.REQ_DEBUNK_NOT_IMPORVE_1);
        this.repository.save(debunker);
        return debunker;
    }


    public ReqDebunker update(ReqDebunker debunker) {
        this.reqDebunkRepositoryExt.update(debunker);
        return debunker;
    }

    public List<ReqDebunker> get(String id, String reqId, String isImprove) {
        return this.repository.findByIdOrReqId(id, reqId, isImprove);
    }
}
